package com.zhangmeng.tools.music.qq;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : 芊芊墨客
 * @version : 1.0
 * @date : 2023-04-22 15:17
 */
public class RequestTemplate{
    public String module="";
    public String method="";
    public Object param=new Object();

    public RequestTemplate() {
    }

    public RequestTemplate(String module, String method, Object param) {
        this.module = module;
        this.method = method;
        this.param = param;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public Object getParam() {
        return param;
    }

    public void setParam(Object param) {
        this.param = param;
    }

    @Override
    public String toString() {
        return "{" +
                "\"module\":\"" + module + "\"" +
                ",\"method\":\"" + method + "\"" +
                ",\"param\":" + param.toString()  +
                "}";
    }
}

/**
 * 构造请求结构，所有请求都可以是这样的
 *
 * {
 *     "comm": {
 *         "ct": 24,
 *         "cv": 0
 *     },
 *     "singerList": {
 *         "module": "Music.SingerListServer",
 *         "method": "get_singer_list",
 *         "param": {
 *             "area": -100,
 *             "sex": -100,
 *             "genre": -100,
 *             "index": -100,
 *             "sin": 0,
 *             "cur_page": 1
 *         }
 *     }
 * }
 */
class RequestTemplateBuilder {
    private Map<String,Object> requestTemplateMap=new HashMap<>();
    public RequestTemplateBuilder add(String name, Object req){
        requestTemplateMap.put(name,req);
        return this;
    }
    @Override
    public String toString() {
        StringBuilder sb=new StringBuilder();
        for (String key: requestTemplateMap.keySet()){
            sb.append("\"").append(key).append("\":").append(requestTemplateMap.get(key).toString()).append(",");
        }
        sb.substring(0,sb.length()-1);
        return "{"+sb.substring(0,sb.length()-1)+"}";
    }
}


